package com.sdgakj.study.thread.pc.quene;

import java.io.Serializable;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * @Author: Du Ronghong
 * @Description:
 * @Date: Created in 18:59 2018/8/28
 * @Modified By:
 */
public class Data implements Serializable {

    private BlockingQueue<Integer> queue = new LinkedBlockingDeque<>(10);
    private int i = 1;

    public void add() {
        try {
            queue.put(i++);
            System.out.println("生产者线程" + Thread.currentThread().getName() + "生产一个资源,当前资源数量:" + queue.size());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public void remove() {
        try {
            queue.take();
            System.out.println("消费者线程" + Thread.currentThread().getName() + "消费一个线程,当前资源数量:" + queue.size());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }


}
